﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace QuangMobile
{
    public partial class UCSearchPanel : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindDataToDropDownList();
                LoadDanhMucSearchPanel();
            }
        }

        private void LoadDanhMucSearchPanel()
        {
            string sql = "Select TOP 4 * from tblWebDanhMuc where MaDM = 'nhom' AND IsShow = 1";
            DataTable dt = SqlHelper.ExecuteDataTable(CommandType.Text, sql);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                ltrDanhMucSearchaPnel.Text += "<a href='NhomSanPham.aspx?mod=" + dt.Rows[i]["ID"] + "'>" + dt.Rows[i]["TenDM"] + "</a> |";
            }
        }

        private void BindDataToDropDownList()
        {
            string sql = "Select * from tblWebDanhMuc where MaDM = 'sp'";
            DataTable dt = SqlHelper.ExecuteDataTable(CommandType.Text, sql);
            ddlTimKiem.DataSource = dt;
            ddlTimKiem.DataTextField = "TenDM";
            ddlTimKiem.DataValueField = "ID";
            ddlTimKiem.DataBind();
            ddlTimKiem.Items.Insert(0, new ListItem("Chọn hãng sản xuất", "-1"));
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string p = txtSearch.Text;
            int Hang = Convert.ToInt32(ddlTimKiem.SelectedValue);
            Response.Redirect("Search.aspx?q=" + p + "&hang=" + Hang);
        }
    }
}